%module wrapper

%{
#include "../include/api.h"
%}

%include "typemaps.i"

%typemap(gotype) (int nCount, char *ticker[]) "[]string"

%typemap(in) (int nCount, char *ticker[])
%{
  {
    int i;
    _gostring_* a;

    $1 = $input.len;
    a = (_gostring_*) $input.array;
    $2 = (char **) malloc (($1 + 1) * sizeof (char *));
    for (i = 0; i < $1; i++) {
      _gostring_ *ps = &a[i];
      char* sz = malloc(sizeof(char)*(ps->n+1));
      memcpy(sz, ps->p, ps->n);
      sz[ps->n+1]='\0';
      $2[i] = sz;
    }
    $2[i] = NULL;
  }
%}

%typemap(argout) (int nCount, char *ticker[]) ""

%typemap(freearg) (int nCount, char *ticker[])
%{
  free($2);
%}

/*****************************************************************************************/

%typemap(gotype) (int nCount, char *ticker2[]) "[]string"

%typemap(in) (int nCount, char *ticker2[])
%{
  {
    int i;
    _gostring_* a;

    $1 = $input.len;
    a = (_gostring_*) $input.array;
    $2 = (char **) malloc (($1 + 1) * sizeof (char *));
    for (i = 0; i < $1; i++) {
      _gostring_ *ps = &a[i];
      char* sz = malloc(sizeof(char)*(ps->n+1));
      memcpy(sz, ps->p, ps->n);
      sz[ps->n+1]='\0';
      $2[i] = sz;
    }
    $2[i] = NULL;
  }
%}

%typemap(argout) (int nCount, char *ticker2[]) ""

%typemap(freearg) (int nCount, char *ticker2[])
%{
  free($2);
%}

%include "../include/api.h"